<template>
    <div id="plus">
        <h1>修改页</h1>
        <el-input v-model="name" placeholder="请输入商品名称"></el-input>
        <el-input v-model="photo" placeholder="请输入商品图片地址"></el-input>
        <el-input v-model="price" placeholder="请输入价格"></el-input>
        <el-input v-model="stock" placeholder="请输入库存"></el-input>
        <el-input v-model=" merchandiseSn" placeholder="请输入规格"></el-input>
        <el-input
                style="margin-top: 20px"
                type="textarea"
                :rows="2"
                placeholder="请输入商品描述"
                v-model="textarea">
        </el-input>
        <el-button @click="resetShopa" type="primary" style="margin-top: 20px">保存</el-button>
    </div>
</template>

<script>
    export default {
        name: "plus",
        data() {
            return {
                name: '',
                photo: '',
                price: '',
                stock: '',
                merchandiseSn: '',
                textarea: '',
                shopList: [],
                id: this.$route.query.id
            }
        },
        created() {
            this.getShop()
            this.tiankong()
        },
        methods: {
            getShop() {
                this.shopList = JSON.parse(localStorage.getItem("shopList"))
                //console.log(this.shopList)
            },
            tiankong() {
                this.name = this.shopList[this.id].brandStoreName
                this.photo = this.shopList[this.id].smallImage
                this.price = this.shopList[this.id].vipshopPrice
                this.stock = this.shopList[this.id].stock
                this.merchandiseSn = this.shopList[this.id].merchandiseSn
                this.textarea =this.shopList[this.id].productName
                console.log(this.shopList)
            },
            resetShopa(){
                var reseted={
                    brandStoreName:this.name,
                    smallImage:this.photo,
                    vipshopPrice:this.price,
                    stock:this.stock,
                    merchandiseSn:this.merchandiseSn,
                    productName:this.textarea
                }
                this.shopList.splice(this.id,1,reseted)
                console.log(this.shopList)
                localStorage.setItem('shopList',JSON.stringify(this.shopList))
                alert('修改成功')
                this.$router.push('/admin')
            }
        }
    }
</script>

<style scoped>
    .el-input {
        margin-top: 10px
    }
</style>